var path = require('path');
var webpack = require('webpack');
var CleanBuild = require('clean-webpack-plugin');
//定义了一些文件夹的路径
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'assets');
var BUILD_PATH = path.resolve(ROOT_PATH, 'public');

module.exports = {
    //项目的文件夹 可以直接用文件夹名称 默认会找index.js 也可以确定是哪个文件名字
    entry: {
        main: APP_PATH + '/js/main.js',
        vendors: ['jquery', 'bootstrap'],
        css: APP_PATH + '/css/css.js'
    },

    module: {
        //配置loaders
        loaders: [
            {
                test: /\.styl$/,
                loader: "style!css!stylus"
            },
            {
                test: /\.css$/,
                loader: "style!css"
            },
            {
                test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
                loader: 'url?prefix=fonts/&limit=10000'
            },
            {
                test: require.resolve('jquery'),
                loader: 'expose?jQuery'
            }
        ]
    },

    //输出的文件名 打包成了两个文件一个vendor底层依赖库一个main
    output: {
        path: BUILD_PATH,
        filename: '[name].js'
    },

    resolve: {
        extensions: ['', '.js', '.css', '.styl']
    },

    stylus: {
        use: [require('nib')()],
        import: ['~nib/lib/nib/index.styl']
    },

    plugins: [
        new webpack.ProvidePlugin({
            $: "jquery",
            jquery: "jQuery",
            "windows.jQuery": "jquery"
        }),
        new CleanBuild(['dist', 'build'], {
            verbose: true,
            dry: false
        })

    ]
};
